Skip to content

feat: installable app with offline service worker - #26

Merged
halitsever merged 1 commit into
mainfrom
feat/pwa
Dec 2, 2026
Merged

halitsever merged 1 commit into
mainfrom
feat/pwa

Conversation

@halitsever

Copy link
Copy Markdown
Owner

Makes tools.halit.org an installable web app that keeps working offline.

Manifest

  • One manifest per language: /site.webmanifest (id and start /) and /tr/site.webmanifest (id and start /tr/). Both have scope /, so the Turkish pages and the English ones open inside either installed app. Separate ids mean a Turkish install opens at /tr/ and the two manifests never overwrite each other.
  • display: standalone, white theme and background (from the tokens), the existing 192, 512 and maskable icons, and shortcuts to the first four tools of each language in index order.
  • Each page links its own language's manifest and has apple-mobile-web-app-title; apple-touch-icon and both theme-color metas were already there.

Service worker (src/sw.js, served at /sw.js)

  • Page navigations go network first. The cached copy, or the home page of the language, is used only when the network fails, so a deploy is never hidden behind the cache.
  • CSS, JS, fonts, icons and manifests are served cache first. The build adds ?v=<hash of css and js> to every CSS and JS URL, including module imports, so a worker from an older deploy cannot answer a newer page's assets from its cache.
  • The cache is named tools-<hash>, a hash of every precached file computed in build.mjs. Install precaches all 25 pages plus their scripts, site.css, fonts, icons and manifests (74 files) with cache: "reload", then calls skipWaiting. Activate deletes the other tools-* caches and claims clients.
  • Cross-origin requests (the Cloudflare beacon) are not touched.

Fonts

Geist is now self-hosted from public/fonts/ (the same Google Fonts woff2 subsets, OFL license included), so the font works offline. The CSP drops fonts.googleapis.com and fonts.gstatic.com and adds worker-src 'self'. The only outside connection left is the Cloudflare beacon, which is now exactly what the "How these tools work" copy says.

Install button

A quiet nav button ("Install app" / "Uygulamayı yükle", "Install" / "Yükle" on phones, icon only below 380px) with an inline SVG icon.

  • Chrome, Edge, Samsung Internet: hidden until beforeinstallprompt, then it opens the browser's prompt once and hides.
  • iPhone and iPad: shows a short hint, "Tap Share, then Add to Home Screen" / "Paylaş simgesine, ardından Ana Ekrana Ekle'ye dokun", with a share icon.
  • Hidden in the installed app (display-mode: standalone or navigator.standalone) and in browsers with no install path (Firefox, desktop Safari).

Checks

  • npm test: 183 pass.
  • node scripts/browser-check.mjs (the full check): passed locally this time.
  • New npm run check:pwa (scripts/pwa-check.mjs): manifests are linked and valid on every page, and Chrome's Page.getAppManifest reports no errors. Page.getInstallabilityErrors is empty for / and /tr/ (run in a real profile). The worker registers with scope / and precaches everything. With the server down and the context offline, all 25 pages load with CSS and Geist, text compare still runs, and an unknown /tr/ URL falls back to /tr/. A changed page shows at once while the network is up, and a new worker hash replaces the old cache. The install button covers the fake prompt at 1280 and 390, standalone mode and the iOS hint. No console or CSP errors.

@halitsever
halitsever merged commit a593e60 into main Dec 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant